package com.hayato.demo.dao;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.hayato.demo.client.Info.CategoryInfo;
import com.hayato.demo.utils.PMF;

public class CategoryDao {

	public List<CategoryInfo> findAllCategory1() {

		return findCategory( Long.parseLong( "0" ) );
	}

	public List<CategoryInfo> findCategory2( Long parentId ) {
		return findCategory( parentId );
	}

	public List<CategoryInfo> findCategory( Long parentId ) {
		
		PersistenceManager pm = PMF.get().getPersistenceManager();

		Query query = pm.newQuery( CategoryInfo.class );
		query.setFilter( "parent_id == parentIdParam" );
		query.declareParameters( "Long parentIdParam" );

		try {
			return ( List<CategoryInfo> ) query.execute( parentId );
		} finally {
			query.closeAll();
		}
	}
}
